﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YTSK.Model;

namespace YTSK.cSK
{
    /// <summary>
    /// 本地税盘发票开具
    /// </summary>
    public class SoftSel
    {
        /// <summary>
        /// 开始开具发票
        /// </summary>
        public static string proc(Model.SK_SalebillVouch sk,
            List<Model.SK_SalebillVouchs_View> l_sks)
        {
            var err = "";

            #region 开票

            string fpdm = "";
            string fphm = "";
            var cbilltype = (FpType) Enum.Parse(typeof(FpType), sk.cBillType);

            var sksetsoft = cSK.cSKSet.loadsave(SkConfig.税控软件名称);
            var sksoft = (SKSoftName) Enum.Parse(typeof(SKSoftName), sksetsoft);
            if (sksoft == SKSoftName.百望)
            {
                err = cSK.BW.Swith.proc(cbilltype, sk, l_sks, out fpdm, out fphm);
            }
            else if (sksoft == SKSoftName.航天)
            {
                err = cSK.HT.Swith.proc(cbilltype, sk, l_sks, out fpdm, out fphm);
            }
            else if (sksoft == SKSoftName.UKey)
            {
                err = cSK.UKey.Swith.proc(cbilltype, sk, l_sks, out fpdm, out fphm);
            }
            else if (sksoft == SKSoftName.百旺新版)
            {
                err = cSK.BWNew.Swith.proc(cbilltype, sk, l_sks, out fpdm, out fphm);
            }
            else if (sksoft == SKSoftName.航天新版)
            {
                err = cSK.HTNew.Swith.proc(cbilltype, sk, l_sks, out fpdm, out fphm);
            }

            #endregion

            #region 回写

            if (err.Length > 0)
            {
                return err;
            }

            System.Threading.Thread.Sleep(1000);
            var fback = new FrmKP.FrmReturn_SK(sk, l_sks, fpdm, fphm, false);
            fback.ShowDialog();
            if (fback.bSuc)
            {
                return "";
            }
            else
            {
                err += "发票回写出现错误。";
            }

            #endregion

            return err;
        }
    }
}